package com.origin.ebuy.forg.web.controller.user;

import com.origin.ebuy.bargd.service.good.IgoodService;
import com.origin.ebuy.bargd.service.good.impl.GoodServiceImpl;
import com.origin.ebuy.forg.web.BaseServlet;
import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class QueryGoodsServlet
 */
public class QueryGoodsServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public QueryGoodsServlet() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		super.doPost(request, response);
		IgoodService  service = new GoodServiceImpl();
		String type = request.getParameter("type");
		//查询单个
		if("1".equals(type)){
			String id = request.getParameter("id");
			try {
				response.getWriter().print(service.queryGood(id));
			} catch (SQLException e) {
				e.printStackTrace();
			}
		//前台查询
		}else if("2".equals(type)){
			try {
				response.getWriter().print(service.fgqueryGoods());
			} catch (SQLException e) {
				e.printStackTrace();
			}
		//后台查询
		}else{
			try {
				request.setAttribute("list",service.queryGoods());
			} catch (SQLException e) {
				e.printStackTrace();
			}
			request.getRequestDispatcher("goodlist.jsp")
			.forward(request, response);
			;
		}
	}

}
